/*
 * Times over
 *
 * Developed: Thomas Georg
 * Created on 26. April 2008, 15:07
 */

import java.applet.Applet;
import java.applet.AudioClip;
import java.awt.Dimension;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.net.URL;

/**
 *
 * @author  Tom
 */
public class countdown_over extends javax.swing.JFrame  {
    

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	AudioClip sound;
	private global_values values = null;
	private  Mywindowlistener kleinerhoerer;
	countwatch watch = new countwatch();
	public global_values getValues() {
		return values;
	}


	public void setValues(global_values values) {
		this.values = values;
	}


	/** Creates new form hallo */
    public countdown_over(global_values values) {
		// TODO Auto-generated constructor stub
    	this.values=values;
    	
    	
    	values.addAdListener(watch);
    	watch.setsound(sound);
    	watch.set_fenster(this);
    	watch.values=values;
        initComponents();
        

        kleinerhoerer = new Mywindowlistener();
        addWindowListener(kleinerhoerer);
        
        	URL f = countdown_over.class.getResource("teaisready.wav");

		
		kleinerhoerer.sound=sound;

				sound = Applet.newAudioClip(f);	
     
    }
    
    
    public void playsound()
    {
				kleinerhoerer.sound=sound;
				watch.setsound(sound);
				sound.loop();
				values=null;
				
    }

    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    
    private void initComponents() {
    	setResizable(false);
    	setTitle("TeaIsReady");
    	setAlwaysOnTop(true);
    	
        jLabel1 = new javax.swing.JLabel();
        gobutton = new javax.swing.JButton();
        gobutton.setText("Switch off Alarm");
        gobutton.setVisible(true);
        gobutton.setAlignmentX(10);
        gobutton.setAlignmentY(10);
        Dimension fenstergroesse = new Dimension();
        fenstergroesse.setSize(10, 10);
        
       
        setBackground(new java.awt.Color(255, 255, 255));
        setBounds(new java.awt.Rectangle(400, 400, 0, 0));
        setMaximumSize(fenstergroesse);
        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 18));
        jLabel1.setForeground(new java.awt.Color(102, 153, 255));
        jLabel1.setText("It's time to drink your tea!");

        
        gobutton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                exit(evt);
            }
        });
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
        		layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        		.addGroup(layout.createSequentialGroup()
        				.addGap(10, 10, 10)
        				.addComponent(jLabel1))
        		.addGroup(layout.createSequentialGroup()
        			.addGap(50, 50, 50)
        				.addComponent(gobutton)
        				.addContainerGap(36, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
        		.addGap(29, 29, 29)
        		.addComponent(jLabel1))
            .addGroup(layout.createSequentialGroup()
                .addGap(75, 75, 75)
                .addComponent(gobutton)
                .addContainerGap(30, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    

    public void exit(java.awt.event.MouseEvent evt)
	{
	 setVisible(false);
	 sound.stop();
	}
   
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JButton gobutton;
    // End of variables declaration//GEN-END:variables
    
}

class Mywindowlistener extends WindowAdapter
{
	AudioClip sound;
	public boolean stop = false;
	public void windowClosing(WindowEvent e)
	{
	 stop=true;
	 sound.stop();
	 sound=null;
	 
	}
}

class countwatch implements changelistener{
	
	AudioClip sound;
	countdown_over fenster = null;
	global_values values=null;
	public void set_fenster(countdown_over fenster)
	{
		this.fenster=fenster;
	}
	public void setsound(AudioClip sound)
	{
		this.sound=sound;
	}

	@Override
	public void changeevent(changeEvent event) {
		// TODO Auto-generated method stub
		System.out.println("Hallo "+event.getSlogan());
		
		if(sound!=null)
			{
			sound.stop();
			
			}
		if(fenster!=null)
		{
			fenster.setVisible(false);
			
		}
		

		
	} 
  } 
